#include<bits/stdc++.h>
using namespace std;
long long tc;
long long n,m,L,V;
long long d[100005],v[100005],a[100005];
long long p[100005];
vector<pair<long long,long long> > seg;
long long sum[100005];
long long lft[100005];
void AC()
{
    for(long long i=1;i<=n+1;i++)
        sum[i]=0;
    for(long long i=1;i<=n+1;i++)
        lft[i]=-1;
    seg.clear();
}
bool check(long long i,long long mid)
{
    long long s=p[mid]-d[i];
    if(s<0)
        return 0;
    long long num=v[i]*v[i]+2*a[i]*s;
    if(num<=V*V)
        return 0;
    return 1;
}
long long Bin(long long i)
{
    long long l=lower_bound(p,p+m+1,d[i])-p,h=m;
    while(l<h)
    {
        long long mid=(l+h+1)/2;
        if(check(i,mid))
            h=mid;
        else
            l=mid+1;
    }
    return l;
}
long long Bin2(long long i)
{
    long long l=lower_bound(p,p+m+1,d[i])-p,h=m;
    while(l<h)
    {
        long long mid=(l+h)/2;
        if(check(i,mid))
            l=mid;
        else
            h=mid-1;
    }
    return l;
}
int main()
{
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    p[0]=-1;
    scanf("%lld",&tc);
    while(tc--)
    {
        scanf("%lld",&n);
        scanf("%lld",&m);
        scanf("%lld",&L);
        scanf("%lld",&V);
        AC();
        for(long long i=1;i<=n;i++)
        {
            scanf("%lld",&d[i]);
            scanf("%lld",&v[i]);
            scanf("%lld",&a[i]);
        }
        for(long long i=1;i<=m;i++)
            scanf("%lld",&p[i]);
        for(long long i=1;i<=n;i++)
        {
            if(a[i]==0)
            {
                if(v[i]>V)
                {
                    long long ll=lower_bound(p,p+m+1,d[i])-p;
                    if(ll>0&&ll<=m)
                    {
                        //cout<<ll<<" "<<m<<" "<<seg.size()<<endl;
                        seg.push_back(make_pair(ll,m));
                    }
                }
            }
            else if(a[i]>0)
            {
                if(check(i,m)==0)
                    continue;
                //cout<<"1"<<endl;
                long long ll=Bin(i);
                //cout<<ll<<" "<<m<<" "<<seg.size()<<" "<<check(i,ll)<<" "<<check(i,m)<<endl;
                if(check(i,ll)&&check(i,m))
                    seg.push_back(make_pair(ll,m));
            }
            else
            {
                if(v[i]<=V)
                    continue;
                long long ll=lower_bound(p,p+m+1,d[i])-p;
                if(ll>0&&ll<=m)
                {
                    if(check(i,ll)==0)
                        continue;
                    //cout<<"2"<<endl;
                    long long rr=Bin2(i);
                    //cout<<ll<<" "<<rr<<" "<<seg.size()<<endl;
                    if(check(i,ll)&&check(i,rr))
                        seg.push_back(make_pair(ll,rr));
                }
            }
        }
        //for(long long i=0;i<seg.size();i++)
        //    cout<<seg[i].first<<" "<<seg[i].second<<endl;
        for(long long i=0;i<seg.size();i++)
            lft[seg[i].second]=max(seg[i].first,lft[seg[i].second]);
        long long ans=0;
        for(long long i=1;i<=m;i++)
        {
            sum[i]=sum[i-1];
            if(lft[i]<=i&&lft[i]>=0)
            {
                if(sum[i]-sum[lft[i]-1]==0)
                {
                    sum[i]++;
                    ans++;
                    //cout<<i<<endl;
                }
            }
        }
        cout<<seg.size()<<" "<<m-ans<<endl;
    }
    return 0;
}